package com.app.shortvideo.ui.video.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.bytedance.sdk.shortplay.api.ShortPlayFragment

class VideoListAdapter(fragmentA: FragmentActivity?) :
    FragmentStateAdapter(fragmentA!!){
    private val fragments: MutableList<ShortPlayFragment> = ArrayList()

    override fun createFragment(position: Int): Fragment {
        return fragments[position]
    }

    override fun getItemCount(): Int {
        return fragments.size
    }

    fun appendData(fragments: MutableList<ShortPlayFragment?>) {
        val size = this.fragments.size
        for (child in fragments){
            child?.let {
                this.fragments.add(child)
            }
        }
        notifyItemRangeInserted(size, fragments.size)
    }
}